<template>
	<view>
		<titlebar mode="我的爱车" :backToIndex="false" :back="true" :text="text" backgroundColor='#f5f5f5'>
			<view slot="title">
				<image class="showMore" mode='aspectFit' v-show="isWatchModel==true" src="@appstatic/community/more.png"
					@click="showMore">

					<view class="showMoreBtn titleCommentTouched" @click="saveBtn" v-show="isWatchModel==false">
						保存
					</view>
					<view class="titleText">{{text}}</view>

			</view>
		</titlebar>
		<showMoreView mode="我的爱车" :isShowMore="isShowMore" @shareAction="editAction" @deleteAction="deleteAction">
		</showMoreView>
		<clxDialog :isShow='deletePopShow' @dialogConfirm='dialogConfirm' @dialogCancel='dialogCancel' :title="title">
		</clxDialog>

		<morePicker :oneList="provinces" :twoList="citys" :defaultValue="defaultValue"
			@morePickerChange="morePickerChange" @closeMorePicker="closeMorePicker"
			@confirmMorePicker="confirmMorePicker" v-show="isShowPicker">
		</morePicker>

		<view class="releaseState" :style="{'top':windowHeight+'px','height':'calc(100% - '+windowHeight+'px)'}">
			<view class="header" id="header">
				<view class="tab-bar" :class="tabIndex==1?'color-1':'color-2'">
					<view @click="changeTab(1)"
						:class="tabIndex==1?'tab-bar-item-clickable tab-bar-item-active':'tab-bar-item-clickable'">车辆信息
					</view>

					<view @click="changeTab(2)"
						:class="tabIndex==2?'tab-bar-item-clickable tab-bar-item-active':'tab-bar-item-clickable'">车主信息
					</view>

					<view @click="changeTab(3)"
						:class="tabIndex==3?'tab-bar-item-clickable tab-bar-item-active':'tab-bar-item-clickable'">终端信息
					</view>

				</view>
			</view>
			<view class="listView">
				<scroll-view :refresher-enabled='false' scroll-y style=" height: 100%;width: 100%">
					<!-- 车辆信息 -->
					<view v-show="tabIndex==1" class="carInfoView">
						<view class="info-transverse">
							<view class="text1">昵称</view>
							<view v-show="isWatchModel==true">
								<view class="text2" v-if="nickName==''||nickName==null">-</view>
								<view class="text2" v-else>{{nickName}}</view>
							</view>
							<input class="text3" v-show="isWatchModel==false" type="text" value='nickName'
								v-model='nickName' data-type='nickName' @input='inputValueChange' placeholder="请输入爱车昵称"
								placeholder-style="color:#ADB0AE" />
						</view>
						<view class="info-transverse">
							<view class="text1">车架号</view>

							<input class="text3" v-if="isWatchModel==false&&isAdd==true" type="text" value='vin'
								v-model='vin' data-type='vin' @input='inputValueChange' @blur="searchInfoByVin" placeholder="请输入车架号"
								placeholder-style="color:#ADB0AE" style="width: 260px;" />

							<view v-else>
								<view class="text2" v-if="vin==''||vin==null">-</view>
								<view class="text2" v-else>{{vin}}</view>
							</view>
						</view>
						<view class="info-transverse" @click.stop="chooseCarType">
							<view class="text1">车系</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="seriesName==''||seriesName==null">-</view>
									<view class="text2" v-else>{{seriesName}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="seriesName==''||seriesName==null">请选择车系</view>
									<view class="text3" v-else>{{seriesName}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>
						<u-picker title="车系" :show="chooseCarTypeShow" :columns="carSeriesList" @confirm="confirmPicker"
							keyName="seriesName" @cancel="cancelPicker" confirmColor="#EA5404">
						</u-picker>

						<view class="info-transverse" @click.stop="chooseBrandModel">
							<view class="text1">车型</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="modelName==''||modelName==null">-</view>
									<view class="text2" v-else>{{modelName}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="modelName==''||modelName==null">请选择车型</view>
									<view class="text3" v-else>{{modelName}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>

						<u-picker title="车型" :show="chooseBrandModelShow" :columns="carModelList"
							@confirm="confirmPicker" keyName="modelName" @cancel="cancelPicker" confirmColor="#EA5404">
						</u-picker>
						
						<view class="info-transverse" @click.stop="chooseConfigure">
							<view class="text1">配置</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="configureName==''||configureName==null">-</view>
									<view class="text2" v-else>{{configureName}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="configureName==''||configureName==null">请选择配置</view>
									<view class="text3" v-else>{{configureName}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>
						<u-picker title="配置" :show="chooseConfigureShow" :columns="CarConfigureList"
							@confirm="confirmPicker" keyName="carConfigName" @cancel="cancelPicker" confirmColor="#EA5404">
						</u-picker>

						<view class="info-transverse">
							<view class="text1">发动机号</view>
							<view v-show="isWatchModel==true">
								<view class="text2" v-if="engineNum==''||engineNum==null">-</view>
								<view class="text2" v-else>{{engineNum}}</view>
							</view>
							<input class="text3" v-show="isWatchModel==false" type="text" value='engineNum'
								v-model='engineNum' data-type='engineNum' @input='inputValueChange'
								placeholder="请输入发动机号" placeholder-style="color:#ADB0AE" />
						</view>

						<view class="info-transverse" @click.stop="chooseProductionTime">
							<view class="text1">生产时间</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="productionTime==''||productionTime==null">-</view>
									<view class="text2" v-else>{{productionTime}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="productionTime==''||productionTime==null">请选择生产时间</view>
									<view class="text3" v-else>{{productionTime}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>

						<u-datetime-picker title="生产时间" :show="productionTimeShow" v-model="valueTime" mode="date"
							@confirm="confirmTime" @cancel="cancelPicker" confirmColor="#EA5404" :maxDate="maxDate">
						</u-datetime-picker>

						<view class="info-transverse" @click.stop="chooseBuyTime">
							<view class="text1">购买时间</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="buyTime==''||buyTime==null">-</view>
									<view class="text2" v-else>{{buyTime}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="buyTime==''||buyTime==null">请选择购买时间</view>
									<view class="text3" v-else>{{buyTime}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>
						<u-datetime-picker title="购买时间" :show="buyTimeShow" v-model="valueTime" mode="date"
							@confirm="confirmTime" @cancel="cancelPicker" confirmColor="#EA5404" :maxDate="maxDate">
						</u-datetime-picker>

						<view v-show="isWatchModel==true" class="info-transverse">
							<view class="text1">交付门店</view>
							<view class="right">
								<view class="text2" v-if="storeName==''||storeName==null">-</view>
								<view class="storeView" v-else>
									<view class="text2">{{storeCity}}</view>
									<view class="text2">{{storeName}}</view>
								</view>

							</view>
						</view>


						<view class="info-transverse" v-show="isWatchModel==false" @click.stop="chooseFranchiser">
							<view class="text1">交付门店</view>
							<view class="right">
								<view class="text2" v-if="storeName==''||storeName==null">请选择交付门店</view>
								<view v-else style="width: 150px;">
									<view
										style="text-align:right;width:100%;min-width: 0;overflow-x: hidden;text-overflow: ellipsis;white-space: nowrap;-webkit-line-clamp: 1;-webkit-box-orient: vertical;">
										{{storeCity}}-{{storeName}}
									</view>
								</view>

								<image class="arrow" src="@appstatic/community/activity_right_arrow.png" />
							</view>
						</view>

					</view>
					<!-- 车主信息 -->
					<view v-show="tabIndex==2" class="carInfoView">
						<view class="info-transverse">
							<view class="text1">车主姓名</view>
							<view v-show="isWatchModel==true">
								<view class="text2" v-if="vehicleOwnerName==''||vehicleOwnerName==null">-</view>
								<view class="text2" v-else>{{vehicleOwnerName}}</view>
							</view>
							<input class="text3" v-show="isWatchModel==false" type="text" value='vehicleOwnerName'
								v-model='vehicleOwnerName' data-type='vehicleOwnerName' @input='inputValueChange'
								placeholder="请输入车主姓名" placeholder-style="color:#ADB0AE" disabled="true" />
						</view>
						<view class="info-transverse" @click.stop="chooseOwnerSex">
							<view class="text1">车主性别</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="vehicleOwnerSex==''||vehicleOwnerSex==null">-</view>
									<view class="text2" v-else>{{vehicleOwnerSex}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="vehicleOwnerSex==''||vehicleOwnerSex==null">请选择车主性别</view>
									<view class="text3" v-else>{{vehicleOwnerSex}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>
						<u-picker title="车主性别" :show="chooseOwnerSexShow" :columns="sexList" @confirm="confirmPicker"
							@cancel="cancelPicker" confirmColor="#EA5404"></u-picker>
						<view class="info-transverse" @click="chooseArea">
							<view class="text1">地区</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="ownerArea==''||ownerArea==null">-</view>
									<view class="text2" v-else>{{ownerArea}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="ownerArea==''||ownerArea==null">请选择地区</view>
									<view class="text3" v-else>{{ownerArea}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>
						<view class="info-transverse" @click="chooseOwnerAge">
							<view class="text1">车主年龄</view>
							<view class="right">
								<view v-show="isWatchModel==true">
									<view class="text2" v-if="ownerAge==''||ownerAge==null">-</view>
									<view class="text2" v-else>{{ownerAge}}</view>
								</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="ownerAge==''||ownerAge==null">请选择车主年龄</view>
									<view class="text3" v-else>{{ownerAge}}</view>
								</view>
								<image class="arrow" src="@appstatic/community/activity_right_arrow.png"
									v-show="isWatchModel==false" />
							</view>
						</view>

						<u-picker title="车主年龄" :show="chooseOwnerAgeShow" :columns="ageList" @confirm="confirmPicker"
							@cancel="cancelPicker" confirmColor="#EA5404"></u-picker>
						<view class="info-transverse">
							<view class="text1">身份证号</view>
							<view v-show="isWatchModel==true">
								<view class="text2" v-if="ownerIDCard==''||ownerIDCard==null">-</view>
								<view class="text2" v-else>
									{{ownerIDCard.substr(0, 4) + '**********' + ownerIDCard.substr(14)}}
								</view>
							</view>
							<input class="text3" v-show="isWatchModel==false" type="idcard" value='ownerIDCard'
								maxlength="18" v-model='ownerIDCard' data-type='ownerIDCard' @input='inputValueChange'
								placeholder="请输入身份证号" placeholder-style="color:#ADB0AE" />
						</view>

						<view class="info-transverse">
							<view class="text1">手机号</view>
							<view v-show="isWatchModel==true">
								<view class="text2" v-if="mobile==''||mobile==null">-</view>
								<view class="text2" v-else>{{mobile}}</view>
							</view>
							<input class="text3" v-show="isWatchModel==false" type="number" value='mobile'
								maxlength="11" v-model='mobile' data-type='mobile' @input='inputValueChange'
								placeholder="请输入手机号" placeholder-style="color:#ADB0AE" disabled="true"/>
						</view>

					</view>
					<!-- 终端信息 -->
					<view v-show="tabIndex==3" class="carInfoView">
						<view class="info-transverse">
							<view class="text4">TBOX</view>

							<block v-if="isWatchModel==true">
								<block v-if="isAdd==false">
									<view class="text-5" @click.stop="bindDevice" v-if="isBind==0">
										绑定终端
									</view>
									<view class="text-5" @click.stop="unBindCar" v-else>
										解绑终端
									</view>
								</block>
							</block>


						</view>


						<view class="info-transverse" v-if="isAdd==true||isBind==0">
							<view class="text1">SN 号</view>
							<view v-show="isWatchModel==false&&isAdd==false">
								<view class="text2" v-if="deviceId==''||deviceId==null">-</view>
								<view class="text2" v-else>{{deviceId}}</view>
							</view>
							<input class="text3" v-show="isWatchModel==true||isAdd==true" type="number" value='deviceId'
								v-model='deviceId' data-type='deviceId' @input='inputValueChange' placeholder="请输入SN 号"
								placeholder-style="color:#ADB0AE" />
						</view>

						<view class="info-transverse" v-else>
							<view class="text1">SN 号</view>
							<view class="text2" v-if="deviceId==''||deviceId==null">-</view>
							<view class="text2" v-else>{{deviceId}}</view>
						</view>







						<block v-if="isAdd==false">
							<view class="info-transverse" v-if="isBind==0">
								<view class="text1">IMEI 号</view>
								<view v-show="isWatchModel==false">
									<view class="text2" v-if="IMEIcode==''||IMEIcode==null">-</view>
									<view class="text2" v-else>{{IMEIcode}}</view>
								</view>
								<input class="text3" v-show="isWatchModel==true" type="number" value='IMEIcode'
									v-model='IMEIcode' data-type='IMEIcode' @input='inputValueChange'
									placeholder="请输入IMEI号" placeholder-style="color:#ADB0AE" />
							</view>



							<view class="info-transverse" v-else>
								<view class="text1">IMEI 号</view>
								<view class="text2" v-if="IMEIcode==''||IMEIcode==null">-</view>
								<view class="text2" v-else>{{IMEIcode}}</view>
							</view>


						</block>





						<block v-if="isBind==1||(isAdd==false&&isWatchModel==false)">

							<view class="info-transverse" v-if="isBind!=0">
								<view class="text1">副卡 ICCID 号</view>
								<view class="text2" v-if="ICCIDcode==''||ICCIDcode==null">-</view>
								<view class="text2" v-else>{{ICCIDcode}}</view>
							</view>

							<view class="info-transverse" v-if="isBind!=0">
								<view class="text1">副卡 IMSI 号</view>
								<view class="text2" v-if="IMSIcode==''||IMSIcode==null">-</view>
								<view class="text2" v-else>{{IMSIcode}}</view>
							</view>

							<view class="info-transverse" v-if="isBind!=0">
								<view class="text1">副卡 SIM 号</view>
								<view class="text2" v-if="SIMcode==''||SIMcode==null">-</view>
								<view class="text2" v-else>{{SIMcode}}</view>

							</view>

						</block>


						<view class="info-transverse" v-if="isAdd==false&&isBind==1">
							<view class="text1">绑定时间</view>
							<view class="text2" v-if="bindTime==''">-</view>
							<view class="text2" v-else>{{bindTime}}</view>
						</view>



						<!-- <view class="info-transverse" v-if="isAdd==false">
							<view class="text1">最后上线时间</view>
							<view class="text2" v-if="lastOnlineTime==''">-</view>
							<view class="text2" v-else>{{lastOnlineTime}}</view>
						</view> -->


					</view>

				</scroll-view>
			</view>

		</view>
	</view>

	</view>


</template>
<script>
	const app = getApp();
	const util = require('@utils/util.js');
	const network = require('@manager/network-manager.js');
	import showMoreView from '@components/showMoreView';
	import clxDialog from "@components/clx-dialog/clx-dialog";
	import morePicker from '@/components/morePicker.vue'
	import moment from 'dayjs'
	export default {
		data() {
			return {
				valueTime: Number(new Date()),
				chooseCarTypeShow: false,
				carSeriesList: [],
				chooseBrandModelShow: false,
				carModelList: [],
				chooseConfigureShow:false,//配置
				CarConfigureList:[],
				productionTimeShow: false,
				buyTimeShow: false,
				deletePopShow: false,
				chooseOwnerSexShow: false,
				sexList: [
					['男', '女']
				],
				chooseOwnerAgeShow: false,
				ageList: [
					['20岁以下', '20-35岁', '35-50岁', '50岁以上']
				],
				provinces: [], //省
				citys: [], //市
				province: '',
				provinceCode: '',
				city: '',
				cityCode: '',
				isShowPicker: false,
				defaultValue: [0, 0], //默认值
				title: '确认删除该车辆吗？',
				isWatchModel: true, //是否是浏览模式， true：浏览没事；    false：编辑模式
				text: '我的爱车',
				windowHeight: app.globalData.statusBarHeight + 44,
				isShowMore: false,
				tabIndex: 1,

				id: '',
				//车辆信息
				nickName: '',
				vin: '',
				seriesName: '',
				seriesId: '',
				modelName: '',
				modelId: '',
				configureName: '',
				configureId: '',
				engineNum: '',
				productionTime: '',
				buyTime: '',
				storeName: '',
				storeId: '',
				storeCity: 'beij',

				//车主信息
				vehicleOwnerName: '',
				vehicleOwnerSex: '',
				ownerArea: '',
				ownerAge: '',
				ownerIDCard: '',
				mobile: '',
				cmobileId: '',

				//终端信息
				deviceId: '',
				IMEIcode: '',
				ICCIDcode: '',
				IMSIcode: '',
				SIMcode: '',
				bindTime: '',
				lastOnlineTime: '',

				isAdd: false,
				isBind: '',
				userInfo: app.globalData.userInfo,
				maxDate: new Date().getTime(),
				showLoading: true

			}
		},
		components: {
			showMoreView,
			clxDialog,
			morePicker
		},
		onLoad: function(options) {
			var that = this

			if (options.from == "add") {
				that.isWatchModel = false
				that.isAdd = true
				//初始化车主信息
				that.vehicleOwnerName = that.userInfo.userName
				that.vehicleOwnerSex = that.userInfo.sex
				that.province = that.userInfo.province
				that.city = that.userInfo.city
				that.mobile = that.userInfo.phone
				that.getProvinceCityInfoByCityName(that.userInfo.city)
			} else {
				that.vin = options.vin
				that.isWatchModel = true
			}
			that.getProvinces()

			that.getLevcCarSeriesList()



		},

		onShow() {
			if (this.isAdd == false) {
				if (this.showLoading == true) {
					this.queryVehicleInfo()
				}
			}

		},

		methods: {
			//根据cityName查询对应信息
			getProvinceCityInfoByCityName: function(city) {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_GET_PROVINCE_CITY_INFO_BY_CITYNAME;
				var params = {
					"cityName": city
				}
				console.log(params, 'params')
				network.get(uri, params, 'json').then(res => {
					if (res.code == 200) {
						that.provinceCode = res.data.provinceCode
						that.cityCode = res.data.cityCode
						that.city = res.data.cityName
						that.cmobileId = res.data.cmobileId

						if (that.province == that.city) {
							that.ownerArea = that.city
						} else {
							that.ownerArea = that.province + " " + that.city
						}


					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				}).catch(res => {

				});
			},
			//门店回调
			getStoreNameData(item) {
				this.storeName = item.storeName
				this.storeCity = item.cityName
				this.storeId = item.uuid
			},
			//解绑回调
			getBindSuccessInfo: function() {
				this.showLoading = true
			},
			// 查询车辆车主信息_转菊花
			queryVehicleInfo: function() {
				var that = this;
				that.showLoading = false
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_QUERYVEHICLEINFO;
				var params = {
					vin: that.vin
				};
				console.log(params, 'params')
				network.get(uri, params, 'form', null, true).then(res => {
					if (res.code == 200) {
						//车辆信息
						that.nickName = res.data.vehicleName
						if (that.nickName == "") {
							that.nickName = res.data.modelName
						}
						that.vin = res.data.vin
						that.seriesName = res.data.seriesName
						that.seriesId = res.data.seriesId
						that.modelName = res.data.modelName
						that.modelId = res.data.modelId
						that.configureName=res.data.configureName
						that.configureId=res.data.configureId
						that.engineNum = res.data.engineNumber
						that.productionTime = res.data.produceTime
						that.buyTime = res.data.purchaseTime
						that.storeName = res.data.storeName
						// that.cityName=res.data.cityName
						that.storeId = res.data.storeId
						that.storeCity = res.data.storeCityName
						//车主信息
						that.vehicleOwnerName = res.data.vehicleOwnerName
						if (res.data.vehicleOwnerSex == 0) {
							this.vehicleOwnerSex = "男"
						} else if (res.data.vehicleOwnerSex == 1) {
							this.vehicleOwnerSex = "女"
						}

						that.ownerAge = that.ageList[0][parseInt(res.data.vehicleOwnerAgeId) - 1]
						that.ownerIDCard = res.data.idCard
						that.mobile = res.data.userMobile
						that.province = res.data.provinceName
						that.provinceCode = res.data.province
						that.city = res.data.cityName
						that.cityCode = res.data.city
						that.cmobileId = res.data.provinceId

						if (that.province == that.city) {
							that.ownerArea = that.city
						} else {
							that.ownerArea = that.province + " " + that.city
						}

						//终端信息
						that.deviceId = res.data.deviceId
						that.IMEIcode = res.data.imei
						that.ICCIDcode = res.data.iccid
						that.IMSIcode = res.data.imsi
						that.SIMcode = res.data.sim
						that.lastOnlineTime = res.data.lastOnlineTime
						that.bindTime = res.data.bindDeviceTime
						that.id = res.data.id

						// that.isBind = res.data.isBind

						if (that.deviceId == null || that.deviceId == '' || that.deviceId == undefined) {
							that.isBind = 0
						} else {
							that.isBind = 1
						}
						if (that.isBind == 1) {
							that.queryIotSimInfo()
						}

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			//新增车辆车主信息到本地
			addVehicleInfoToLocal: function() {
				var that = this;

				var ownerSex = 0
				if (that.vehicleOwnerSex == "男") {
					ownerSex = 0
				} else if (that.vehicleOwnerSex == "女") {
					ownerSex = 1
				}
				var ownerAgeId = 0
				if (that.ownerAge == '20岁以下') {
					ownerAgeId = 1
				} else if (that.ownerAge == '20-35岁') {
					ownerAgeId = 2
				} else if (that.ownerAge == '35-50岁') {
					ownerAgeId = 3
				} else if (that.ownerAge == '50岁以上') {
					ownerAgeId = 4
				}

				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_ADDVEHICLEINFOTOLOCAL;
				var params = {
					"vehicleName": that.nickName,
					"vin": that.vin,
					"engineNumber": that.engineNum,
					"produceTime": that.productionTime,
					"purchaseTime": that.buyTime,
					"bindTime": that.bindTime,
					"bindDeviceTime": that.bindTime,
					"deviceId": that.deviceId,
					"iccid": that.ICCIDcode,
					"imei": that.IMEIcode,
					"userId": app.getUserId(),
					"imsi": that.IMSIcode,
					"sim": that.SIMcode,
					"modelName": that.modelName,
					"modelId": that.modelId,
					"seriesName": that.seriesName,
					"seriesId": that.seriesId,
					"storeName": that.storeName,
					"storeId": that.storeId,
					"vehicleOwnerName": that.vehicleOwnerName,
					"vehicleOwnerSex": ownerSex,
					"vehicleOwnerAgeId": ownerAgeId,
					"idCard": that.ownerIDCard,
					"userMobile": that.mobile,
					"province": that.provinceCode,
					"provinceName": that.province,
					"city": that.cityCode,
					"cityName": that.city,
					"provinceId": that.cmobileId,
					"count": 0,
					"createTime": moment(),
					"deleteFlag": 0,
					"factoryModelCode": "",
					"isAdd": 0,
					// "isBind": 0,
					"isDefault": 0,
					"lastOnlineTime": moment(),



				};
				console.log(params, 'params')
				network.post(uri, params, 'json').then(res => {
					if (res.code == 200) {
						this.isAdd = false
						this.isWatchModel = true
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},

			//新增车辆车主信息
			addVehicleInfo: function() {
				var that = this;
				    
				if(that.nickName == '') {
					uni.showToast({
						title: "请输入昵称",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				else if (that.vin == '') {
					uni.showToast({
						title: "请输入车架号",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.seriesName == '') {
				 	uni.showToast({
				 		title: "请输入车系",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.modelName == '') {
				 	uni.showToast({
				 		title: "请输入车型",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.configureName == '') {
				 	uni.showToast({
				 		title: "请输入配置",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.engineNum == '') {
				 	uni.showToast({
				 		title: "请输入发动机号",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.productionTime == '') {
					uni.showToast({
						title: "请选择生产时间",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.buyTime == '') {
					uni.showToast({
						title: "请选择购买时间",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.storeName=='' || that.storeName == null) {
				 	uni.showToast({
				 		title: "请选择交付门店",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				} else if (that.vehicleOwnerName == '') {
					uni.showToast({
						title: "请输入车主姓名",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.vehicleOwnerSex == '') {
					uni.showToast({
						title: "请选择车主性别",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.cmobileId == '') {
					uni.showToast({
						title: "请选择省份",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.ownerAge == '') {
					uni.showToast({
						title: "请选择车主年龄",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.ownerIDCard == '') {
					uni.showToast({
						title: "请输入身份证号",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.mobile == '') {
					uni.showToast({
						title: "请输入手机号",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.deviceId == '') {
					uni.showToast({
						title: "请输入SN号",
						duration: 3000,
						icon: 'none'
					})
					return
				}


				var ownerSex = 0
				if (that.vehicleOwnerSex == "男") {
					ownerSex = 0
				} else if (that.vehicleOwnerSex == "女") {
					ownerSex = 1
				}
				var ownerAgeId = 0
				if (that.ownerAge == '20岁以下') {
					ownerAgeId = 1
				} else if (that.ownerAge == '20-35岁') {
					ownerAgeId = 2
				} else if (that.ownerAge == '35-50岁') {
					ownerAgeId = 3
				} else if (that.ownerAge == '50岁以上') {
					ownerAgeId = 4
				}

				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_ADDVEHICLEINFO;
				var params = {
					"vehicleName": that.nickName,
					"vin": that.vin,
					"engineNumber": that.engineNum,
					"produceTime": that.productionTime,
					"purchaseTime": that.buyTime,
					"bindTime": moment().format("YYYY-MM-DD HH:mm:ss"),
					"bindDeviceTime": moment().format("YYYY-MM-DD HH:mm:ss"),
					"deviceId": that.deviceId,
					"iccid": that.ICCIDcode,
					"imei": that.IMEIcode,
					"lastOnlineTime": that.lastOnlineTime,
					"userId": app.getUserId(),
					"imsi": that.IMSIcode,
					"sim": that.SIMcode,
					"configureId":that.configureId,//配置
					"configureName":that.configureName,
					"modelName": that.modelName,
					"modelId": that.modelId,
					"seriesName": that.seriesName,
					"seriesId": that.seriesId,
					"storeName": that.storeName,
					"storeCityName": that.storeCity,
					"storeId": that.storeId,
					"vehicleOwnerName": that.vehicleOwnerName,
					"vehicleOwnerSex": ownerSex,
					"vehicleOwnerAgeId": ownerAgeId,
					"idCard": that.ownerIDCard,
					"userMobile": that.mobile,
					"province": that.provinceCode,
					"provinceName": that.province,
					"city": that.cityCode,
					"cityName": that.city,
					"provinceId": that.cmobileId

				};
				console.log(params, 'params')
				network.post(uri, params, 'json', null, true).then(res => {
					if (res.code == 200) {
						this.isAdd = false
						this.isWatchModel = true

						// this.showLoading = true
						this.queryVehicleInfo()





					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},


			//修改车辆车主信息
			updateVehicleInfo: function() {
				var that = this;

				if(that.nickName == '') {
					uni.showToast({
						title: "请输入昵称",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				else if (that.vin == '') {
					uni.showToast({
						title: "请输入车架号",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.seriesName == '') {
				 	uni.showToast({
				 		title: "请输入车系",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.modelName == '') {
				 	uni.showToast({
				 		title: "请输入车型",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.configureName == '') {
				 	uni.showToast({
				 		title: "请输入配置",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.engineNum == '') {
				 	uni.showToast({
				 		title: "请输入发动机号",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				 }else if (that.productionTime == '') {
					uni.showToast({
						title: "请选择生产时间",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.buyTime == '') {
					uni.showToast({
						title: "请选择购买时间",
						duration: 3000,
						icon: 'none'
					})
					return
				}else if (that.storeName=='' || that.storeName == null) {
				 	uni.showToast({
				 		title: "请选择交付门店",
				 		duration: 3000,
				 		icon: 'none'
				 	})
				 	return
				}else if (that.vehicleOwnerName == '') {
					uni.showToast({
						title: "请输入车主姓名",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.vehicleOwnerSex == '') {
					uni.showToast({
						title: "请选择车主性别",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.cmobileId == '') {
					uni.showToast({
						title: "请选择省份",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.ownerAge == '') {
					uni.showToast({
						title: "请选择车主年龄",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.ownerIDCard == '') {
					uni.showToast({
						title: "请输入身份证号",
						duration: 3000,
						icon: 'none'
					})
					return
				} else if (that.mobile == '') {
					uni.showToast({
						title: "请输入手机号",
						duration: 3000,
						icon: 'none'
					})
					return
				}

				var ownerSex = 0
				if (that.vehicleOwnerSex == "男") {
					ownerSex = 0
				} else if (that.vehicleOwnerSex == "女") {
					ownerSex = 1
				}
				var ownerAgeId = 0
				if (that.ownerAge == '20岁以下') {
					ownerAgeId = 1
				} else if (that.ownerAge == '20-35岁') {
					ownerAgeId = 2
				} else if (that.ownerAge == '35-50岁') {
					ownerAgeId = 3
				} else if (that.ownerAge == '50岁以上') {
					ownerAgeId = 4
				}

				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_UPDATEVEHICLEINFO;
				var params = {
					"id": that.id,
					"vehicleName": that.nickName,
					"vin": that.vin,
					"engineNumber": that.engineNum,
					"produceTime": that.productionTime,
					"purchaseTime": that.buyTime,
					"bindTime": that.bindTime,
					"bindDeviceTime": that.bindTime,
					"deviceId": that.deviceId,
					"iccid": that.ICCIDcode,
					"imei": that.IMEIcode,
					"lastOnlineTime": that.lastOnlineTime,
					"userId": app.getUserId(),
					"imsi": that.IMSIcode,
					"sim": that.SIMcode,
					"configureId":that.configureId,//配置
					"configureName":that.configureName,
					"modelName": that.modelName,
					"modelId": that.modelId,
					"seriesName": that.seriesName,
					"seriesId": that.seriesId,
					"storeName": that.storeName,
					"storeCityName": that.storeCity,
					"storeId": that.storeId,
					"vehicleOwnerName": that.vehicleOwnerName,
					"vehicleOwnerSex": ownerSex,
					"vehicleOwnerAgeId": ownerAgeId,
					"idCard": that.ownerIDCard,
					"userMobile": that.mobile,
					"province": that.provinceCode,
					"provinceName": that.province,
					"city": that.cityCode,
					"cityName": that.city,
					"provinceId": that.cmobileId
				};
				console.log(params, 'params')
				network.post(uri, params, 'json', null, true).then(res => {
					if (res.code == 200) {
						this.isWatchModel = true
						this.queryVehicleInfo()
						
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},

			//查询物联卡流量到期时间
			queryIotSimInfo: function() {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_QUERYIOTSIMINFO;
				var params = {
					deviceId: that.deviceId
				};
				console.log(params, 'params', null, true)
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.ICCIDcode = res.data.iccid
						that.IMSIcode = res.data.imsi
						that.SIMcode = res.data.sim

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			//获取车系列表
			getLevcCarSeriesList: function() {
				var that = this;

				var uri = app.globalData.config.interfaces.URL_CAR_SERIES_LIST;
				var params = {
					statusFlag: 0
				};
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.carSeriesList = [res.data]

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			//获取车型列表
			getLevcCarModelList: function() {
				var that = this;

				var uri = app.globalData.config.interfaces.URL_CAR_MODEL_LIST;
				var params = {
					statusFlag: 0,
					seriesId: that.seriesId
				};
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.carModelList = [res.data]

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			//获取配置列表
			getLevcCarConfigureList: function() {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_CAR_CONFIG_LIST;
				var params = {
					statusFlag: 2,
					carModelId: that.modelId           
				};
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.CarConfigureList = [res.data]
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},

			//删除用车
			deleteCarById: function() {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_DELETECAR;
				var params = {
					vin: that.vin
				};
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: "删除成功",
							duration: 3000,
							icon: 'none',
							success: () => {
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									})
								}, 2000)
							}
						})

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},

			//监听输入
			inputValueChange: function(e) {
				let type = e.currentTarget.dataset.type
				let value = e.detail.value
				if (type == 'mobile') {
					value = Number(value.toString().match(/^\d+(?:\.\d{0,2})?/)[0])
					this.$nextTick(() => {
						this.formData[type] = value
					})
				}
			},
			//根据车架号查信息
			searchInfoByVin: function(e) {
				var that=this
				let value = e.detail.value
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_QUERYVEHICLEINFO;
				var params = {
					vin: e.detail.value
				};
				network.get(uri, params, 'form', null, true).then(res => {
					if (res.code == 200) {
						that.seriesName = res.data.seriesName
						that.seriesId = res.data.seriesId
						that.modelName = res.data.modelName
						that.modelId = res.data.modelId
						that.configureName= res.data.configureName
						that.configureId= res.data.configureId
						that.storeName = res.data.storeName
						that.storeId = res.data.storeId
						that.storeCity = res.data.storeCityName
					}else{
						uni.showToast({
							title: '此车架号不存在',
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			
			//点击右上角查看更多...
			showMore: function() {
				this.isShowMore = !this.isShowMore
			},
			//编辑
			editAction: function() {
				this.isShowMore = false
				this.isWatchModel = false
			},
			//删除
			deleteAction: function() {
				this.isShowMore = false
				this.deletePopShow = true
			},
			//保存
			saveBtn: function() {
				if (this.isAdd == true) {

					this.addVehicleInfo()
				} else {
					this.updateVehicleInfo()
				}

			},
			//确定删除
			dialogConfirm() {
				this.deletePopShow = false
				this.deleteCarById()
			},
			//取消删除
			dialogCancel() {
				this.deletePopShow = false
			},
			//点击teb页签
			changeTab: function(val) {
				this.tabIndex = val
			},
			//选择车系
			chooseCarType: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.chooseCarTypeShow = true
			},
			//选择车型
			chooseBrandModel: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.chooseBrandModelShow = true
				// uni.navigateTo({
				// 	url: "/module_car/chooseBrand/chooseBrand",
				// });
			},
			//选择配置
			chooseConfigure: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.chooseConfigureShow = true
				// uni.navigateTo({
				// 	url: "/module_car/chooseBrand/chooseBrand",
				// });
			},
			//选择生产时间
			chooseProductionTime: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.productionTimeShow = true
			},
			//选择购买时间
			chooseBuyTime: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.buyTimeShow = true
			},


			//选择经销商
			chooseFranchiser: function() {
				uni.navigateTo({
					url: "/module_car/chooseFranchiser/chooseFranchiser",
				});
			},
			//绑定车辆
			bindDevice() {

				var that = this;
				if (that.vin == '' || that.vin == null) {
					uni.showToast({
						title: "请输入车架号",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				if (that.deviceId == '' || that.deviceId == null) {
					uni.showToast({
						title: "请输入SN号",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				if (that.IMEIcode == '' || that.IMEIcode == null) {
					uni.showToast({
						title: "请输入IMEI号",
						duration: 3000,
						icon: 'none'
					})
					return
				}
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_BINDDEVICE;
				var params = {
					vin: that.vin,
					deviceId: that.deviceId,
					imei: that.IMEIcode
				};
				console.log(params, 'params')
				network.post(uri, params, 'form').then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: "绑定成功",
							duration: 3000,
							icon: 'none'
						})
						that.isBind = 1
						this.queryVehicleInfo()

					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				})
			},
			//解绑车辆
			unBindCar: function() {
				uni.navigateTo({
					url: "/module_car/unbindCar/unbindCar?vin=" + this.vin + "&deviceId=" + this.deviceId,
				});
			},
			//选择车主性别
			chooseOwnerSex: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.chooseOwnerSexShow = true
			},
			//选择车主年龄 
			chooseOwnerAge: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.chooseOwnerAgeShow = true
			},

			//选择车主地区
			chooseArea: function() {
				if (this.isWatchModel == true) {
					return
				}
				this.isShowPicker = true
			},
			//地址选择变化
			morePickerChange(e) {
				const val = e.detail.value;
				if (this.defaultValue[0] !== val[0]) {
					this.defaultValue = [val[0], 0]; //省变，后面的都默认选第一个
					this.getProvinces();
				} else if (this.defaultValue[1] !== val[1]) {
					this.defaultValue = [val[0], val[1]]; //市变，后面的默认第一个
					this.getCitys();
				} else {
					this.defaultValue = val;
				}
			},
			//取消选取
			closeMorePicker() {
				this.isShowPicker = false;
			},
			//确认选取
			confirmMorePicker() {
				this.isShowPicker = false;
				//省
				if (this.provinces[this.defaultValue[0]].id) {
					this.province = this.provinces[this.defaultValue[0]].provinceName;
					this.provinceCode = this.provinces[this.defaultValue[0]].provinceCode;
					this.cmobileId = this.provinces[this.defaultValue[0]].cmobileId;
				}
				//市
				if (this.citys[this.defaultValue[1]].id) {
					this.city = this.citys[this.defaultValue[1]].cityName;
					this.cityCode = this.citys[this.defaultValue[1]].cityCode;
				}
				if (this.province == this.city) {
					this.ownerArea = this.city
				} else {
					this.ownerArea = this.province + " " + this.city
				}


			},
			//获取省接口
			getProvinces: function() {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_GET_PROVINCE;
				var params = {
					"loginId": app.getUserId()
				}
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.provinces = res.data.ProvinceList
						this.getCitys();
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				}).catch(res => {

				});
			},
			//获取市
			getCitys: function() {
				var that = this;
				var uri = app.globalData.config.interfaces.URL_GET_CITY_BY_PROVINCE;
				var params = {
					"loginId": app.getUserId(),
					"provinceCode": this.provinces[this.defaultValue[0]].provinceCode
				}
				console.log(params, 'params')
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.citys = res.data.cityList
					} else {
						uni.showToast({
							title: res.message,
							duration: 3000,
							icon: 'none'
						})
					}
				}).catch(res => {

				});
			},

			//确定-选择下拉框
			confirmPicker: function(e) {
				if (this.chooseCarTypeShow == true) {
					this.chooseCarTypeShow = false
					this.seriesName = e.value[0].seriesName
					this.seriesId = e.value[0].uuid
					this.modelName = ''
					this.modelId = ''
					this.configureId = ''
					this.configureName = ''
					this.getLevcCarModelList()
					this.getLevcCarConfigureList()
				}
				if (this.chooseBrandModelShow == true) {
					this.chooseBrandModelShow = false
					this.modelName = e.value[0].modelName
					this.modelId = e.value[0].uuid
					this.configureId = ''					this.configureName = ''
					this.getLevcCarConfigureList()
				}
				if(this.chooseConfigureShow == true) {
					debugger
					this.chooseConfigureShow = false
					this.configureName = e.value[0].carConfigName
					this.configureId = e.value[0].id
				}


				if (this.chooseOwnerSexShow == true) {
					this.chooseOwnerSexShow = false
					this.vehicleOwnerSex = e.value[0]
				}
				if (this.chooseOwnerAgeShow == true) {
					this.chooseOwnerAgeShow = false
					this.ownerAge = e.value[0]
				}
			},
			//确定-时间下拉选择框
			confirmTime: function(e) {
				const timeFormat = uni.$u.timeFormat
				if (this.productionTimeShow == true) {
					this.productionTime = timeFormat(e.value, 'yyyy-mm-dd')
					this.productionTimeShow = false
				}
				if (this.buyTimeShow == true) {
					this.buyTime = timeFormat(e.value, 'yyyy-mm-dd')
					this.buyTimeShow = false
				}
			},
			//取消-下拉框
			cancelPicker: function() {
				if (this.productionTimeShow == true) {
					this.productionTimeShow = false
				}
				if (this.buyTimeShow == true) {
					this.buyTimeShow = false
				}
				if (this.chooseCarTypeShow == true) {
					this.chooseCarTypeShow = false
				}
				if (this.chooseBrandModelShow == true) {
					this.chooseBrandModelShow = false
				}
				if(this.chooseConfigureShow == true) {//配置
					this.chooseConfigureShow = false
				}


				if (this.chooseOwnerSexShow == true) {
					this.chooseOwnerSexShow = false
				}
				if (this.chooseOwnerAgeShow == true) {
					this.chooseOwnerAgeShow = false
				}
			},

		}
	}
</script>
<style>
	@import "./myCarEdit.css";
</style>
